package com.haohan.jingyuan.user.service;

import com.haohan.jingyuan.user.dao.ResourcesInfoMapper;
import com.haohan.jingyuan.user.dto.req.QueryResourceListRequest;
import com.haohan.jingyuan.user.dto.resp.ResourceInfoResp;
import com.haohan.jingyuan.user.dto.resp.ResourceListResp;
import com.haohan.jingyuan.user.entity.ResourcesInfo;
import com.haohan.jingyuan.user.helper.ResourceInfoRespHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资源服务实现类
 *
 * @ClassName ResourceService
 * @Description 资源相关业务逻辑实现
 * @Author hexijun
 * @Time 2025/11/05 14:00
 * @Version 1.0
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ResourceService {

    /**
     * 资源信息Mapper
     */
    private final ResourcesInfoMapper resourcesInfoMapper;

    /**
     * 查询资源列表
     *
     * @param request 查询资源列表请求
     * @return 资源列表
     */
    public ResourceListResp queryResourceList(QueryResourceListRequest request) {
        // 根据父级资源ID查询资源列表
        List<ResourcesInfo> resourcesList = resourcesInfoMapper.selectByParentId(request.getParentId());

        // 转换为响应对象
        List<ResourceInfoResp> resourceRespList = ResourceInfoRespHelper.convert2ResourceInfoRespList(resourcesList);

        ResourceListResp response = new ResourceListResp();
        response.setResourceList(resourceRespList);
        return response;
    }
}

